package com.example.utils.util;

import java.io.IOException;
import java.lang.reflect.Field;

/**
 * TODO  自定义的判空方法
 *
 * @ClassName StringNullUtil
 * @Author xiaojiang
 * @Date 2021/9/26 下午 15:19
 */
public class StringNullUtil {

    public static boolean isEmpty(String str) {
        return null == str || "\"\"".equals(str.trim()) || "".equals(str.trim()) || "null".equals(str.trim()) || "NaN".equals(str.trim());
    }

    public static boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }

    public static void main(String[] args) throws IOException {

        String a = "    ";
        System.out.println(StringNullUtil.isEmpty(a));

    }

    // String 进行内存转换
    static void swap(String a, String b) throws NoSuchFieldException, IllegalAccessException {
        Class<? extends String> aClass = a.getClass();
        Class<? extends String> bClass = b.getClass();

        Field aValue = aClass.getDeclaredField("value");
        Field bValue = bClass.getDeclaredField("value");

        aValue.setAccessible(true);
        bValue.setAccessible(true);

        char[] aChars = (char[]) aValue.get(a);
        char[] bChars = (char[]) bValue.get(b);

        for (int i = 0; i < aChars.length; i++) {
            char temp = aChars[i];
            aChars[i] = temp;
            bChars[i] = aChars[i];
        }

    }

}
